#include <iostream>
using namespace std;

int a[3][3], tx, to;

int judge()
{
	if (tx < to || tx-to > 1) return 4;
	bool ju[2];
	ju[0] = ju[1] = false;
	for (int i = 0; i != 3; ++i)
		if (a[i][0] && a[i][0] == a[i][1] && a[i][1] == a[i][2])
			ju[a[i][0] - 1] = true;
	for (int i = 0; i != 3; ++i)
		if (a[0][i] && a[0][i] == a[1][i] && a[1][i] == a[2][i])
			ju[a[0][i] - 1] = true;
	if (a[0][0] && a[0][0] == a[1][1] && a[1][1] == a[2][2])
		ju[a[0][0] - 1] = true;
	if (a[0][2] && a[0][2] == a[1][1] && a[1][1] == a[2][0])
		ju[a[0][2] - 1] = true;
	if (ju[0] && ju[1]) return 4;
	if (ju[0] && tx == to) return 4;
	if (ju[1] && tx > to) return 4;
	if (ju[0]) return 0;
	if (ju[1]) return 1;
	if (tx + to == 9) return 2;
	return 3;
}

int main()
{
	for (int i = 0; i != 3; ++i)
		for (int j = 0; j != 3; ++j) {
			char ch;
			cin >> ch;
			if (ch == 'X') a[i][j] = 1, ++tx;
			if (ch == '0') a[i][j] = 2, ++to;
		}

	int tmp = judge();
	if (tmp == 0)
		cout << "the first player won" << endl;
	if (tmp == 1)
		cout << "the second player won" << endl;
	if (tmp == 2)
		cout << "draw" << endl;
	if (tmp == 3) {
		if (to == tx)
			cout << "first" << endl;
		else
			cout << "second" << endl;
	}
	if (tmp == 4) {
		cout << "illegal" << endl;
	}
}
